/* -*-c++-*- */
/* osgGIS - GIS Library for OpenSceneGraph
 * Copyright 2007-2008 Glenn Waldron and Pelican Ventures, Inc.
 * http://osggis.org
 *
 * osgGIS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 */

#ifndef _OSGGIS_OGR_FEATURESTORE_H_
#define _OSGGIS_OGR_FEATURESTORE_H_ 1

#include <osgGIS/Common>
#include <osgGIS/FeatureStore>
#include <osgGIS/SpatialReference>
#include <string>
#include <sys/types.h>

namespace osgGIS
{
    /* (internal)
     *
     * FeatureStore implementation that uses the OGR library to access vector data.
     */
	class OGR_FeatureStore : public osgGIS::FeatureStore
	{
	public:
		OGR_FeatureStore(const std::string& uri );
		
        OGR_FeatureStore(
            const std::string&         abs_path,
            const GeoShape::ShapeType& shape_type,
            const AttributeSchemaList& schemas,
            int                        dimensionality,
            const SpatialReference*    srs,
            const Properties&          props );
		
	public: // osgGIS::FeatureStore
	
		bool isReady() const;

        const std::string& getName() const;
		
		SpatialReference* getSRS() const;
	
		Feature* getFeature( const FeatureOID& oid );
		
		FeatureCursor getCursor();
		
		int getFeatureCount() const;
		
		const GeoExtent& getExtent() const;

        bool supportsRandomRead() const;

        Feature* createFeature() const;
                        
        bool insertFeature( Feature* input );
        
        const AttributeSchemaTable& getAttributeSchemas();

        const time_t getModTime() const;
		
	public:
		virtual ~OGR_FeatureStore();
		
	private:
        std::string uri;
		void* ds_handle;
		void* layer_handle;
		osg::ref_ptr<SpatialReference> spatial_ref;
		GeoExtent extent;
        bool supports_random_read;
        AttributeSchemaTable schema;
        time_t mtime;
        
        void calcExtent();
	};
}

#endif // _OSGGIS_OGR_FEATURESTORE_H_

